﻿using System;
using ApiGateway;
using HttpApiGateway.Model;
using RpcClient;
using RpcHelper.Validate;

using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Gateway.Model;
using Wedonek.RpcStore.Service.Model;
namespace Wedonek.RpcStore.Gateway.Controller
{
    /// <summary>
    /// 任务管理
    /// </summary>
    internal class AutoTaskController : HttpApiGateway.ApiController
    {
        private readonly IAutoTaskService _AutoTask = null;

        public AutoTaskController(IAutoTaskService task)
        {
            this._AutoTask = task;
        }
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="task">任务信息</param>
        /// <returns>任务Id</returns>
        public Guid Add(AddAutoTask task)
        {
            return this._AutoTask.AddAutoTask(task);
        }
        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="id">任务Id</param>
        public void Drop([NullValidate("rpc.task.id.null")] Guid id)
        {
            this._AutoTask.DropAutoTask(id);
        }
        /// <summary>
        /// 获取任务详细
        /// </summary>
        /// <param name="id">任务Id</param>
        /// <returns>任务详细</returns>
        public AutoTaskList Get([NullValidate("rpc.task.id.null")] Guid id)
        {
            return this._AutoTask.GetAutoTask(id);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="param">查询参数</param>
        /// <returns>任务列表</returns>
        public PagingResult<AutoTaskDatum> Query(PagingParam<QueryTaskParam> param)
        {
            AutoTaskDatum[] list = this._AutoTask.QueryTask(param, out long count);
            return new PagingResult<AutoTaskDatum>(count, list);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="param">修改信息</param>
        public void Set(SetAutoTask param)
        {
            this._AutoTask.SetAutoTask(param);
        }
    }
}
